<template>

  <div class="app-container">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          size="mini"
          @click="getContractList"
        >合同查询</el-button>
      </el-col>
    <el-form ref="form" :model="form" :rules="rules" label-width="80px">
      <el-form-item label="商户" prop="businessId">
        <el-input v-model="form.businessId" placeholder="请输入商户ID" />
      </el-form-item>
      <el-form-item label="合同" prop="contractId">
        <el-input v-model="form.contractId" placeholder="请输入合同ID" />
      </el-form-item>
      <el-form-item label="合同编号" prop="contractNo">
        <el-input v-model="form.contractNo" placeholder="请输入合同编号" />
      </el-form-item>
      <el-form-item label="小区" prop="premiseName">
        <el-input v-model="form.premiseName" placeholder="请输入小区(使用楼盘名)" />
      </el-form-item>
      <el-form-item label="业主姓名" prop="ownerName">
        <el-input v-model="form.ownerName" placeholder="请输入业主姓名" />
      </el-form-item>
      <el-form-item label="租客姓名" prop="tenantName">
        <el-input v-model="form.tenantName" placeholder="请输入租客姓名(面向业主收款时，为空)" />
      </el-form-item>
      <el-form-item label="其它款项" prop="otherItemName">
        <el-input v-model="form.otherItemName" placeholder="请输入其它款项,款项为其它的时候，输入" />
      </el-form-item>
      <el-form-item label="支付金额" prop="paymentAmount">
        <el-input v-model="form.paymentAmount" placeholder="请输入支付金额" />
      </el-form-item>
      <el-form-item label="实收金额" prop="realPaymentAmount">
        <el-input v-model="form.realPaymentAmount" placeholder="请输入实收金额" />
      </el-form-item>
      <el-form-item label="选择账期" prop="withReceiptPlanId">
        <el-input v-model="form.withReceiptPlanId" placeholder="请输入选择账期" />
      </el-form-item>
      <el-form-item label="第几期" prop="receiptNumber">
        <el-input v-model="form.receiptNumber" placeholder="请输入第几期" />
      </el-form-item>
      <el-form-item label="线下支付方式" prop="payMethod">
        <el-input v-model="form.payMethod" placeholder="请输入线下支付方式" />
      </el-form-item>
      <el-form-item label="其它支付方式" prop="otherPayMethod">
        <el-input v-model="form.otherPayMethod" placeholder="请输入其它支付方式,支付方式为其它的时候，输入" />
      </el-form-item>
      <el-form-item label="支付流水号" prop="payFlowNo">
        <el-input v-model="form.payFlowNo" placeholder="请输入支付流水号" />
      </el-form-item>
      <el-form-item label="账期房租金额" prop="rentalPrice">
        <el-input v-model="form.rentalPrice" placeholder="请输入账期房租金额" />
      </el-form-item>
      <el-form-item label="税费" prop="tax">
        <el-input v-model="form.tax" placeholder="请输入税费" />
      </el-form-item>
      <el-form-item label="操作人" prop="operationUser">
        <el-input v-model="form.operationUser" placeholder="请输入操作人" />
      </el-form-item>
      <el-form-item label="备注" prop="remark">
        <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
      </el-form-item>
      <el-form-item label="创建用户" prop="createUserid">
        <el-input v-model="form.createUserid" placeholder="请输入创建用户ID" />
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="submitForm">新增收付款</el-button>
      <el-button @click="cancel">取 消</el-button>
    </div>

    <el-dialog title="收货地址" :visible.sync="dialogTableVisible">
    <el-table v-loading="loading" :data="contractList" @selection-change="handleSelectionChange">
<!--      <el-table-column type="selection" width="55" align="center" />-->
<!--      <el-table-column label="主键id" align="center" prop="id" />-->
      <el-table-column label="合同编号" align="center" prop="sfContractNo" />
      <!--      <el-table-column label="上一合同ID，续约合同的时候" align="center" prop="lastContractId" />-->
      <!--      <el-table-column label="上一合同编号" align="center" prop="lastContractNo" />-->
<!--            <el-table-column label="商户ID" align="center" prop="businessId" />-->
<!--      <el-table-column label="小区名(使用楼盘名称)" align="center" prop="premiseName" />-->
      <!--      <el-table-column label="房产ID" align="center" prop="houseId" />-->
<!--      <el-table-column label="房源标题" align="center" prop="houseTitle" />-->
      <!--      <el-table-column label="房产证书编号" align="center" prop="houseZsNo" />-->
      <el-table-column label="产权地址" align="center" prop="cqAddress" />
      <!--      <el-table-column label="房东ID" align="center" prop="ownerId" />-->
<!--      <el-table-column label="房东姓名" align="center" prop="ownerName" />-->
      <!--      <el-table-column label="房东证件号码" align="center" prop="ownerIdCard" />-->
<!--      <el-table-column label="房东手机号" align="center" prop="ownerMobile" />-->
      <el-table-column label="租户名称" align="center" prop="signUserName" />
      <!--      <el-table-column label="租户人证件号" align="center" prop="signUserIdCard" />-->
      <el-table-column label="租户人手机号" align="center" prop="signUserMobile" />
      <!--      <el-table-column label="租户紧急联系电话" align="center" prop="signUserEmergencyPhone" />-->
<!--      <el-table-column label="租约期限开始时间" align="center" prop="leaseStartTime" width="180">-->
<!--        <template slot-scope="scope">-->
<!--          <span>{{ parseTime(scope.row.leaseStartTime, '{y}-{m}-{d}') }}</span>-->
<!--        </template>-->
<!--      </el-table-column>-->
<!--      <el-table-column label="租约期限结束时间" align="center" prop="leaseEndTime" width="180">-->
<!--        <template slot-scope="scope">-->
<!--          <span>{{ parseTime(scope.row.leaseEndTime, '{y}-{m}-{d}') }}</span>-->
<!--        </template>-->
<!--      </el-table-column>-->
      <!--      <el-table-column label="收房月租金" align="center" prop="monthRent" />-->
      <!--      <el-table-column label="房产押金" align="center" prop="depositMoney" />-->
      <!--      <el-table-column label="支付方式(押X付Y的X)" align="center" prop="depositType" />-->
      <!--      <el-table-column label="支付方式(押X付Y的Y）" align="center" prop="paymentType" />-->
      <!--      <el-table-column label="合同签订时间，" align="center" prop="conSignTime" width="180">-->
      <!--        <template slot-scope="scope">-->
      <!--          <span>{{ parseTime(scope.row.conSignTime, '{y}-{m}-{d}') }}</span>-->
      <!--        </template>-->
      <!--      </el-table-column>-->
<!--      <el-table-column label="合同录入时间，" align="center" prop="conInfoTime" width="180">-->
<!--        <template slot-scope="scope">-->
<!--          <span>{{ parseTime(scope.row.conInfoTime, '{y}-{m}-{d}') }}</span>-->
<!--        </template>-->
<!--      </el-table-column>-->
<!--      <el-table-column label="合同审核时间，" align="center" prop="conAudTime" width="180">-->
<!--        <template slot-scope="scope">-->
<!--          <span>{{ parseTime(scope.row.conAudTime, '{y}-{m}-{d}') }}</span>-->
<!--        </template>-->
<!--      </el-table-column>-->
      <!--      <el-table-column label="合同录入人" align="center" prop="operId" />-->
      <!--      <el-table-column label="收房人，" align="center" prop="sfUserId" />-->
      <!--      <el-table-column label="收房人姓名" align="center" prop="sfUserName" />-->
<!--      <el-table-column label="合同状态" align="center" prop="status">-->
<!--        <template slot-scope="scope">-->
<!--          <span v-if="scope.row.status == 1">草稿</span>-->
<!--          <span v-if="scope.row.status == 2">已提交</span>-->
<!--          <span v-if="scope.row.status == 3">已解约</span>-->
<!--          <span v-if="scope.row.status == 4">已结束</span>-->
<!--          <span v-if="scope.row.status == 9">作废</span>-->
<!--        </template>-->
<!--      </el-table-column>-->
      <!--      <el-table-column label="续约状态" align="center" prop="xyStatus" />-->
<!--      <el-table-column label="是否收房贷" align="center" prop="sfLoanFlg">-->
<!--        <template slot-scope="scope">-->
<!--          <span v-if="scope.row.sfLoanFlg == 0">否</span>-->
<!--          <span v-if="scope.row.sfLoanFlg == 1">是</span>-->
<!--        </template>-->
<!--      </el-table-column>-->

      <!--      <el-table-column label="备注" align="center" prop="remark" />-->
      <!--      <el-table-column label="联系地址" align="center" prop="ownerAddress" />-->
      <!--      <el-table-column label="删除标识" align="center" prop="delFlg">-->
      <!--        <template slot-scope="scope">-->
      <!--          <span v-if="scope.row.delFlg == 0">未删除</span>-->
      <!--          <span v-if="scope.row.delFlg == 1">删除</span>-->
      <!--        </template>-->
      <!--      </el-table-column>-->
      <!--      <el-table-column label="创建用户ID" align="center" prop="createUserid" />-->
      <!--      <el-table-column label="更新用户ID" align="center" prop="updateUserid" />-->
      <!--      <el-table-column label="房产类型" align="center" prop="houseLeaseType">-->
      <!--        <template slot-scope="scope">-->
      <!--          <span v-if="scope.row.houseLeaseType == 1">合租</span>-->
      <!--          <span v-if="scope.row.houseLeaseType == 2">整租</span>-->
      <!--          <span v-if="scope.row.houseLeaseType == 3">公寓</span>-->
      <!--        </template>-->
      <!--      </el-table-column>-->

      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            @click="handleClick(scope.row)"
          >选中</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getContractList"
    />
    </el-dialog>
  </div>

</template>

<script>
import { listPlan, getPlan, delPlan, addPlan, updatePlan } from "@/api/accounting/plan";
import {listContract} from "@/api/contract/contract";

export default {
  name: "Plan",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 【请填写功能名称】表格数据
      dayList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        businessId: null,
        businessName: null,
        onlineFlg: null,
        dealDate: null,
        operationType: null,
        total: null,
        deposit: null,
        rent: null,
        electricityFee: null,
        waterFee: null,
        netFee: null,
        gasFee: null,
        cableFee: null,
        czFee: null,
        otherFee: null,
        reserve1: null,
        reserve2: null,
        reserve3: null,
        reserve4: null,
        reserve5: null,
        delFlg: null,
        createUserid: null,
        updateUserid: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        createTime: []
      },
      dialogTableVisible : false,
    };
  },
  created() {
    // this.getList();
  },
  methods: {
    handleClick(row){
      this.form.contractNo=row.sfContractNo
      this.form.businessId=row.businessId
      this.form.contractId=row.id
      this.form.premiseName=row.premiseName
      this.form.ownerName=row.ownerName
      this.form.tenantName=row.signUserName
      this.dialogTableVisible=false;
    },
    /** 查询【请填写功能名称】列表 */
    getContractList() {
      this.loading = true;
      listContract(this.queryParams).then(response => {
        this.contractList = response.rows;
        this.total = response.total;
        this.loading = false;
        this.dialogTableVisible=true;
      });
    },
    /** 查询收款计划列表 */
    getList() {
      this.loading = true;
      listPlan(this.queryParams).then(response => {
        this.planList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        receiptOrderNo: null,
        businessId: null,
        contractId: null,
        contractNo: null,
        contractType: null,
        tTerminationId: null,
        premiseId: null,
        premiseName: null,
        roomId: null,
        roomCode: null,
        roomName: null,
        ownerId: null,
        ownerName: null,
        tenantId: null,
        tenantName: null,
        receiptType: null,
        skStatus: 0,
        billType: null,
        itemType: null,
        otherItemName: null,
        paymentAmount: null,
        realPaymentAmount: null,
        withReceiptPlanId: null,
        paymentDaysBegin: null,
        paymentDaysEnd: null,
        collectionDate: null,
        realCollectionDate: null,
        receiptNumber: null,
        payMethod: null,
        otherPayMethod: null,
        payFlowNo: null,
        rentalPrice: null,
        tax: null,
        operationUser: null,
        remark: null,
        reserve1: null,
        reserve2: null,
        reserve3: null,
        reserve4: null,
        reserve5: null,
        delFlg: null,
        createUserid: null,
        createTime: null,
        updateUserid: null,
        updateTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加收款计划";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getPlan(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改收款计划";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updatePlan(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addPlan(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除收款计划编号为"' + ids + '"的数据项？').then(function() {
        return delPlan(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('accounting/plan/export', {
        ...this.queryParams
      }, `plan_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
